/*
 **************************************************************************
 *                Confidentiality Information:                    
 *                                                                
 * This module is the confidential and proprietary information of 
 * CottSoft.com; it is not to be copied, reproduced, or         
 * transmitted in any form, by any means, in whole or in part,    
 * nor is it to be used for any purpose other than that for which 
 * it is expressly provided without the written permission of     
 * CottSoft.com.                                                
 *                                                                
 **************************************************************************
 *                                                               
 * PROGRAM DESCRIPTION:
 *                                                 
 * This filter is processing Chinese code. 
 * 
 * 
 *                                 
 **************************************************************************
 * CHANGE HISTORY: 
 * 
 * Date:       	by:    			Reason:                                     
 * YYYY-MM-DD  	IN     			Reason text.                                
 *           
 * 2010-11-28   Simon Hoo		Initial Version.
 *************************************************************************
 */

package com.satchi.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CharacterEncodingFilter implements Filter {
	private String encoding = null;

	public void init(FilterConfig filterConfig) throws ServletException {
		this.encoding = filterConfig.getInitParameter("encoding");
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filterChain) throws IOException, ServletException {
		request.setCharacterEncoding(encoding);
		response.setContentType("text/html;charset=" + encoding);
		filterChain.doFilter(request, response);
	}

	public void destroy() {
		// destroy code.
	}
}